package com.soft.util;

import com.soft.app.ruanba.dao.SoftDAO;
import com.soft.app.ruanba.down.Soft;

public class DatabaseHelper {
	private static SoftDAO dao = new SoftDAO();
	private RegexpHelper regex;
	private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DatabaseHelper.class);

	public DatabaseHelper()
	{
		regex = new RegexpHelper();
	}

	
	public void save(Soft soft)
	{
		org.hibernate.Transaction t = dao.getSession().beginTransaction();
		dao.save(soft);
		t.commit();
	}

	private boolean validate(Soft temp)
	{
		if (org.apache.commons.lang.StringUtils.isBlank(temp.getName()))
		{
			log.warn("Soft:{} 的数据不满足要求", temp);
			return false;
		} else
		{
			return true;
		}
	}

	private java.lang.String format(java.util.List list)
	{
		java.lang.StringBuffer sb = new StringBuffer();
		boolean isFirst = true;
		if (list != null)
		{
			for (java.util.Iterator i$ = list.iterator(); i$.hasNext();)
			{
				java.lang.String str = (java.lang.String)i$.next();
				if (isFirst)
				{
					sb.append(str);
					isFirst = false;
				} else
				{
					sb.append(" | ").append(str);
				}
			}

		}
		return sb.toString();
	}

	private java.lang.String findReleaseDate(java.lang.String text)
	{
		if (org.apache.commons.lang.StringUtils.isBlank(text))
			return null;
		else
			return regex.extractDate(text);
	}

	public long countSofts(java.lang.String status)
	{
		return dao.countAll(status);
	}

	public java.util.List getSoftList(int start, int size, java.lang.String status)
	{
		return dao.getSoftList(start, size, status);
	}
}
